package com.md.controller;

import com.md.entity.Flowers;
import com.md.service.flowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flowers")
@CrossOrigin
public class flowerController {
    @Autowired
    private flowerService flowerService;
    @GetMapping()
    public List<Flowers> selectAll() {
        return flowerService.selectAll();
    }
    @GetMapping("{id}")
    public Flowers selectOneById(@PathVariable String id) {
        return flowerService.selectOneById(Integer.valueOf(id));
    }
    @GetMapping(params = "name")
    public List<Flowers> selectOneByName(String name) {
        System.out.println(name);
        return flowerService.selectOneByName(name);
    }
    @PostMapping()
    public String insert(@RequestBody Flowers flowers) {
        return flowerService.insert(flowers) ? "添加成功":"添加失败";
    }
    @DeleteMapping("{id}")
    public String delete(@PathVariable int id) {
        return flowerService.delete(id) ? "删除成功":"删除失败";
    }
    @PutMapping()
    public String update(@RequestBody Flowers flowers) {
        System.out.println(flowers);
        return flowerService.update(flowers) ? "ok":"no";
    }
}
